package chapter04

/**
 * 范围数据循环（To）
 */
object Test02_ForLoop {
  def main(args: Array[String]): Unit = {
    for (i <- 1 to 10) {
      println(i + " :HELLO WORD")
    }

    for (i: Int <- 1.to(10)) {
      println("HELLO WORD: " + i)
    }

    //到9
    for (i <- Range(1, 10)) {
      println(i + " :HELLO WORD")
    }

    //到九的第二种方式
    for (i <- 1 until 10) {
      println(i + " :HELLO WORD")
    }


    //遍历集合
    for (i <- Array(12, 32, 121, 32)) {
      println(i)
    }


    for (i <- List(12, 32, 121, 32)) {
      println(i)
    }

    for (i <- Set(12, 32, 121, 32)) {
      println(i)
    }


    println("#####################")
    //3、循环守卫
    for (i <- 1 to 10 if i != 5) {
      println(i)
    }




    println("#####################")
    //循环步长
    for (i <- 1 to 10 by 2) {
      println(i)
    }

    println("#####################")
    //+3
    for (i <- 13 to 30 by 3) {
      println(i)
    }


    println("#####################")
    //倒序
    for (i <- 1 to 10 reverse) {
      println(i)
    }


    //嵌套循环
    println("#####################")
    for (i <- 1 to 4) {
      for (j <- 1 to 3) {
        println("i = " + i + ", j= " + j)
      }
    }

    println("#####################")
    for (i <- 1 to 4; j <- 1 to 5) {
      println("i = " + i + ", j= " + j)
    }


  }

}
